/**
 * @param {string[]} stickers
 * @param {string} target
 * @return {number}
 */
 var minStickers = function(stickers, target) {
  const base = 'a'.charCodeAt(0);
  let letterMap = new Array(stickers.length).fill(false).map(_ => new Array(26).fill(0));
  const score = new Array(stickers.length).fill(0);
  const totalMap = new Array(26).fill(0);
  let tMap = new Array(26).fill(0);
  for(let i in target) {
    tMap[target.charCodeAt(i) - base]++;
  }
  stickers.map((s, i) => {
    for(let j in s) {
      const code = s.charCodeAt(j) - base;
      tMap[code] > 0 && letterMap[i][code]++ && score[i]++;
      totalMap[code] ++;
    }
  });
  const order = tMap.map((e, i) => i).filter(e => tMap[e] > 0).sort((a, b) => tMap[a] - tMap[b]);
  if(totalMap.some((e, i) => e === 0 && tMap[i] > 0)) return -1;
  console.log(order);
  let s = 0;
  let total = target.length;
  const traverse = (temp, s, total) => {
    let cnt = 0;
    while(total > 0) {
      if(temp[s] === 0) {
        s++;
        continue;
      }
      let cand = [0];
      for(let i = 0; i < stickers.length; i++) {
        if(letterMap[i][s] > letterMap[cand[0]][s]) {
          cand = [i];
        } else if(letterMap[i][s] === letterMap[cand][s] && score[i] > score[cand]) {
          cand = [i];
        } else if(letterMap[i][s] === letterMap[cand][s] && score[i] === score[cand]) {
          cand.push(i);
        }
      }
      if(cand.length === 1) {
        const div = Math.ceil(temp[s] / letterMap[cand[0]][s]);
        for(let i = 0; i < 26; i++) {
          if(temp[i] !== 0) {
            const t = Math.min(temp[i], letterMap[cand[0]][i] * div);
            temp[i] -= t;
            total -= t;
          }
        }
      } else {
        let ret = Infinity;
        for(let c of cand) {
          
        }
      }
      cnt += div;
      s++;
    }
  }
 
  return cnt;
};
console.log(minStickers(
  ["these","guess","about","garden","him"],
  "atomher"))